<?php
/**
 * Whois controller
 * @author Tomas Srna
 * @package bakalarka
 */

class DomainWhoisController extends DomainAbstractController
{
	public function index()
	{
		$t = Template::instance();
		
		$t->title = L::selected()->whois;
		
		$t->plusmenu = $this->plusmenu;
		$t->plusmenu_title = $this->plusmenu_title;
		
		$domain_parts = explode(".", $this->domain);
		$tld = $domain_parts[count($domain_parts)-1];
		$server = $tld . ".whois-servers.net";
		
		if(false !== ($c = @fsockopen($server, 43)))
		{
			$whois = "<pre>";
			fputs($c, $this->domain."\r\n");
			while(!feof($c))
			{
				$whois .= fread($c, 100);
			}
			$whois .= "</pre>";
			fclose($c);
		}
		else
		{
			$whois = L::selected()->notConnected;
		}
		
		$t->text = $whois;
		
		$t->render();
	}
}
